package com.qf.pojo;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.qf.json.MySerializer;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class User {
    //声明   成员变量

    @JsonProperty(value = "new_id") //自定义别名 json
    @JSONField(name = "new_id")
    private Integer id;
    private String name;

    @JsonIgnore // 忽略此属性
    private Boolean gender;

    @DateTimeFormat(pattern = "yyyy:MM:dd HH:mm:ss") //自定义日期格式   K:V  v = request.getParamter(k)
    @JsonFormat(pattern = "yyyy:MM:dd HH:mm:ss",timezone = "GMT+8")
    private Date birth;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String[] hobby;//爱好   [蓝球,羽毛球]

    //工资 薪水  自定义JSON转换规则  MySerializer.class: 自定义规则实现类
    @JsonSerialize(using = MySerializer.class)   //
    private Double salary = 15000.126;

    //则输出json时：{"id":xx,"name":"xxx","salary":15000.13}


    //集合   长度是0也不要   是null不要
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<User> users = new ArrayList<>();


    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", gender=" + gender +
                ", birth=" + birth +
                ", hobby=" + Arrays.toString(hobby) +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getGender() {
        return gender;
    }

    public void setGender(Boolean gender) {
        this.gender = gender;
    }

    public Date getBirth() {
        return birth;
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }

    public String[] getHobby() {
        return hobby;
    }

    public void setHobby(String[] hobby) {
        this.hobby = hobby;
    }
}